package com.hh.front.controller;

import com.hh.common.page.CommonPage;
import com.hh.common.request.PageParamRequest;
import com.hh.common.request.integral.IntegralCreateOrderRequest;
import com.hh.common.response.CommonResult;
import com.hh.common.response.integral.IntegralCateListResponse;
import com.hh.common.response.integral.StoreIntegralDetailResponse;
import com.hh.common.response.integral.StoreIntegralH5Response;
import com.hh.service.service.integral.IntegralOrderService;
import com.hh.service.service.integral.PointsMallService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("api/front/pointsMall")
public class PointsMallController {

    @Autowired
    private PointsMallService pointsMallService;

    @Autowired
    private IntegralOrderService integralOrderService;

    /**
     * 积分商品列表
     * @param cateId
     * @param pageParamRequest
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreIntegralH5Response>> list(Integer cateId, String keyword,@ModelAttribute PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(pointsMallService.getPointsMallList(cateId,keyword,pageParamRequest)));
    }

    /**
     * 积分商品分类
     * @return
     */
    @RequestMapping(value = "/cateList", method = RequestMethod.GET)
    public CommonResult<List<IntegralCateListResponse>> list() {
        return CommonResult.success(pointsMallService.getPointsMallCateList());
    }

    /**
     * 积分商品详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/goodsDetails/{id}", method = RequestMethod.GET)
    public CommonResult<StoreIntegralDetailResponse> goodsDetails(@PathVariable(value = "id") Integer id) {
        return CommonResult.success(pointsMallService.goodsDetails(id));
    }


    /**
     * 积分兑换商品
     * @param orderRequest
     * @return
     */
    @RequestMapping(value = "/exchange", method = RequestMethod.POST)
    public CommonResult<Map<String, Object>> exchange(@Validated @RequestBody IntegralCreateOrderRequest orderRequest) {
        return CommonResult.success(pointsMallService.exchange(orderRequest));
    }

    /**
     * 再兑一单
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/againExchange", method = RequestMethod.POST)
    public CommonResult<Map<String, Object>> againExchange(@RequestParam(value = "orderId") String orderId) {
        return CommonResult.success(pointsMallService.againExchange(orderId));
    }

}
